var boardPaikeCheckedItems;
function getboardPaikeData(type) {
    
    var _type
    
    if(type == "0"){
    
       _type = 1;
    
    }else{ _type = 2; }
    
	var startDate = $("#boardPaikeStartDate").val();
	var endDate = $("#boardPaikeEndDate").val();
    var shuliang = document.getElementById("boardPaikeshuliang").options[document.getElementById("boardPaikeshuliang").selectedIndex].value;
    var pindao = document.getElementById("boardPaikepindao").options[document.getElementById("boardPaikepindao").selectedIndex].value;
	//var osID = document.getElementById("boardPaikeOS").options[document.getElementById("boardPaikeOS").selectedIndex].value;
	var typeID = document.getElementById("boardPaikeType").options[document.getElementById("boardPaikeType").selectedIndex].value;
	//var marketID = document.getElementById("boardPaikeMarket").options[document.getElementById("boardPaikeMarket").selectedIndex].value;
	$(".boardPaikeChart").html("");
	if (startDate != "" && endDate != "")
	{
		var start = new Date();
		var end = new Date();

		//统计项
		var items = document.getElementsByName("boardPaikeCheckbox");
		boardPaikeCheckedItems = new Array();
		for(var i=0;i<items.length;i++) {
			if (items[i].checked)
			{
				boardPaikeCheckedItems.push(items[i].value);
			}
		}

		if(boardPaikeCheckedItems.length > 0) {


			jQuery('#body-wrapper').showLoading();
			start.setFullYear(startDate.substring(0,4), startDate.substring(5,7)-1, startDate.substring(8,10));
			end.setFullYear(endDate.substring(0,4), endDate.substring(5,7)-1 ,endDate.substring(8,10));

			days = parseInt((end - start)/1000/60/60/24)+1;

			var APIurl = "/client/mainboardPaikeAnalytics?staDate="+startDate+"&pd="+days;
	        
            
            if (shuliang != "")
				APIurl += "&shuliang="+shuliang;
			if (pindao != "")
				APIurl += "&pindao="+pindao;
            if (_type != "")
				APIurl += "&type="+_type;

			
			$.ajax({
				type: "GET",
				url: APIurl,
				dataType : "html",
				jsonnp: "callback",
				success:function(data,textStatus){ loadboardPaikeData(data,type)}
			});
		}
		else {
			alert("请选择至少一个统计项");
		}

	}
	else {
		alert("请选择时间区域");
	}
}


var boardPaikeTabArr, boardPaikeDetailArr, boardPaikeSumArr, boardPaikeDateArr, MainSubTitle;
function loadboardPaikeData(data,type) {
	//var osID = document.getElementById("boardPaikeOS").options[document.getElementById("boardPaikeOS").selectedIndex].value;
	//var typeID = document.getElementById("boardPaikeType").options[document.getElementById("boardPaikeType").selectedIndex].value;
	//var marketID = document.getElementById("boardPaikeMarket").options[document.getElementById("boardPaikeMarket").selectedIndex].value;
	var tab = "";
	var startDate = $("#boardPaikeStartDate").val();
	var endDate = $("#boardPaikeEndDate").val();
	MainSubTitle = startDate.replace(/\//g, "-") + " 至 " + endDate.replace(/\//g, "-");
	jQuery('#body-wrapper').hideLoading();	


	boardPaikeTabArr = new Array();
	boardPaikeDetailArr = new Array();
	boardPaikeSumArr = new Array();
	boardPaikeDateArr = new Array();

	
		changeChartType('boardPaike', 'Table');
	
			//显示选择Tab
			genTabsboard("boardPaike", "boardPaikeOS", boardPaikeTabArr, boardPaikeDetailArr, boardPaikeSumArr, boardPaikeCheckedItems,type);
			//读取数据
            
            
            //读取数据
		
            
           
			
       
			
            //readSummaryData(data, boardPaikeDateArr, "type", boardPaikeTabArr, boardPaikeDetailArr, boardPaikeCheckedItems, boardPaikeSumArr);
		

			
            
            $("#boardPaikePieTab").hide();
		$("#boardPaikePie").html("");
        
        
        
        changeChartType('boardPaike','Table');
        
        
        
		
        //alert(boardPaikeTabArr);
        
        //alert(data);
        
        genTop10Tableboard("boardPaikeTable", valueFullNameArr(boardPaikeCheckedItems), boardPaikeTabArr, data, boardPaikeCheckedItems);
        
        
		if ($("#boardPaikePieTab").hasClass("selbitem"))
			changeChartType('boardPaike', 'Line');
            
            
          

		
		
	
}

function changeboardPaikeTab(tabName, optionName) {
	
    
    
    getboardPaikeData(tabName);
    
    
    
    
	$(".bitem").removeClass("selbitem");
	$("#boardPaikeTab"+tabName).addClass("selbitem");	
    
	
}


